﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Expression.Shapes;

namespace Steer
{
    public partial class FlockTest : UserControl
    {
        private List<Vehicle> _vehicles;
        private int _numVehicles = 30;
        public FlockTest()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(FlockTest_Loaded);
        }

        void FlockTest_Loaded(object sender, RoutedEventArgs e)
        {
            _vehicles = new List<Vehicle>();
            for (int i = 0; i < _numVehicles; i++)
            {
                SteeredVehicle vehicle = new SteeredVehicle();
                RegularPolygon rp = new RegularPolygon();
                rp.Width = 15;
                rp.Height = 15;
                rp.Fill = new SolidColorBrush(Colors.Blue);
                rp.PointCount = 3;
                TransformGroup tf = new TransformGroup();
                CompositeTransform ct = new CompositeTransform();
                tf.Children.Add(ct);
                rp.RenderTransform = tf;
                ct.Rotation = 90;
                vehicle.Children.Add(rp);
                vehicle.Width = 15;
                vehicle.Height = 15;
                vehicle.HorizontalAlignment = HorizontalAlignment.Left;
                vehicle.VerticalAlignment = VerticalAlignment.Top;
                LayoutRoot.Children.Add(vehicle);
                _vehicles.Add(vehicle);
            }
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }

        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            foreach (SteeredVehicle vehicle in _vehicles)
            {
                vehicle.flock(_vehicles);
                vehicle.update();
            }
        }
    }
}
